package edu.cmu.javadb.plan.condition;

import java.util.*;

import edu.cmu.javadb.Attribute;
import edu.cmu.javadb.RecordInfo;

public class And extends Condition {

	private Condition[] conditions;
	
	public And(Condition[] conditions) {
		this.conditions = conditions;
	}

//	@Override
//	public List<String> getAllFieldNames() {
//		List<String> res = new ArrayList<String>();
//		
//		for (Condition c : conditions) {
//			res.addAll(c.getAllFieldNames());
//		}
//		return res;
//	}

	@Override
	public boolean satisfy(Object o) {
		boolean res = true;
		for (Condition c : conditions) {
			res = res && c.satisfy(o);
		}
		return res;
	}

	public Condition[] getConditions() {
		return conditions;
	}

	@Override
	public boolean containRootPath() {
		for (Condition c : conditions) {
			if (c.containRootPath())
				return true;
		}
		return false;
	}

	@Override
	public List<Attribute> getAllFields(RecordInfo recInfo) {
		List<Attribute> res = new ArrayList<Attribute>();
		
		for (Condition c : conditions) {
			res.addAll(c.getAllFields(recInfo));
		}
		return res;
	}

	@Override
	public boolean containNonValBinary() {
		for (Condition c : conditions) {
			if (c.containNonValBinary())
				return true;
		}
		return false;
	}
}
